package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.HardWareProductConfig;
import com.ruoyi.system.service.IHardWareProductConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 硬件产品配置Controller
 *
 * @author ruoyi
 * @date 2023-03-26
 */
@RestController
@RequestMapping("/system/product_config")
public class HardWareProductConfigController extends BaseController {
    @Autowired
    private IHardWareProductConfigService hardWareProductConfigService;

    /**
     * 查询硬件产品配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:product_config:list')")
    @GetMapping("/list")
    public TableDataInfo list(HardWareProductConfig hardWareProductConfig) {
        startPage();
        List<HardWareProductConfig> list = hardWareProductConfigService.selectHardWareProductConfigList(hardWareProductConfig);
        return getDataTable(list);
    }

    /**
     * 导出硬件产品配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:product_config:export')")
    @Log(title = "硬件产品配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HardWareProductConfig hardWareProductConfig) {
        List<HardWareProductConfig> list = hardWareProductConfigService.selectHardWareProductConfigList(hardWareProductConfig);
        ExcelUtil<HardWareProductConfig> util = new ExcelUtil<HardWareProductConfig>(HardWareProductConfig.class);
        util.exportExcel(response, list, "硬件产品配置数据");
    }

    /**
     * 获取硬件产品配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:product_config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(hardWareProductConfigService.selectHardWareProductConfigById(id));
    }

    /**
     * 新增硬件产品配置
     */
    @PreAuthorize("@ss.hasPermi('system:product_config:add')")
    @Log(title = "硬件产品配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HardWareProductConfig hardWareProductConfig) {
        return toAjax(hardWareProductConfigService.insertHardWareProductConfig(hardWareProductConfig));
    }

    /**
     * 修改硬件产品配置
     */
    @PreAuthorize("@ss.hasPermi('system:product_config:edit')")
    @Log(title = "硬件产品配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HardWareProductConfig hardWareProductConfig) {
        return toAjax(hardWareProductConfigService.updateHardWareProductConfig(hardWareProductConfig));
    }

    /**
     * 删除硬件产品配置
     */
    @PreAuthorize("@ss.hasPermi('system:product_config:remove')")
    @Log(title = "硬件产品配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(hardWareProductConfigService.deleteHardWareProductConfigByIds(ids));
    }
}
